package com.hzsai.nettylearn.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;

/**
 * hzsai 2019/11/15
 * usage: 伪异步IO server启动器
 **/
@Component
public class FakeAsyncTimeServerStarter {

    @Autowired
    private TimeClient client;

    @Autowired
    private FakeAsyncTimeServer server;

    /**
     * 需要确保server, client已经创建了才能执行
     * 所以这里使用 @PostConstruct注解
     * @throws IOException
     * @throws InterruptedException
     */
    @PostConstruct
    public void postConstruct() throws IOException, InterruptedException {
        Runnable r = () -> {
            try {
                server.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        };
        Thread t = new Thread(r);

        t.start();
        // server.start();
        //client.start();
    }
}
